<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<meta charset="utf-8" />
	<meta name="renderer" content="webkit|ie-comp|ie-stand" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<title>文章管理</title>
	<link rel="stylesheet" href="/plugins/layui/css/layui.css"  media="all" />
	<link rel="stylesheet" href="/plugins/mdeditor/css/editormd.css" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="/plugins/html5shiv.js"></script>
	<script type="text/javascript" src="/plugins/respond.min.js"></script>
	<![endif]-->
	<!--[if IE 6]>
	<script type="text/javascript" src="/plugins/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
</head>
<body >
 <blockquote class="layui-elem-quote">
<span  style="padding-left:10px;" class="layui-breadcrumb" >
  <a th:href="'/essay/textmanage/'+${valid }"  th:text="${valid}==0?'草稿管理':'文章管理'"  ></a>
  <a><cite><span th:text="${text.type.uid}==1?'修改标准文章':'修改MarkDown'"  /></cite></a>
    <button style="float:right;" onclick="location.reload();" class="layui-btn layui-btn-small"><i class="layui-icon">&#x1002;</i></button>
</span>
</blockquote>
<form id= "textForm" class="layui-form" method="post">
<input type="hidden"  id="uid"  name="uid"  th:value="${uid}"/>
<input type="hidden"  id="typeid"  name="typeid"  th:value="${text.type.uid}"/>
<input type="hidden"  id="valid"   name="valid"  th:value="${valid}"/>
<input type="hidden"  id="content"   name="content" />
<div  style="padding-top:10px;" class="layui-form-item">
<div class="layui-inline">
    <label class="layui-form-label">标题</label>
    <div class="layui-input-block">
      <input style="width:400px;" type="text" id="title"  name="title" lay-verify="required" 
      autocomplete="off" placeholder="请输入文章标题" class="layui-input"  th:value="${text.title}"/>
    </div>
</div>
<div class="layui-inline">
      <label class="layui-form-label">所属栏目</label>
      <div class="layui-input-inline">
        <select id="classid" name="classid" lay-verify="required" lay-search="">
          <option  th:each="cl:${classificationList}"  th:value="${cl.uid}"  th:text="${cl.name}"  th:selected ="${text.classification.uid == cl.uid}?'selected':''"/>
        </select>
      </div>
    </div>
  </div>
  <div style="width:95%;" class="layui-form-item">
    <label class="layui-form-label">缩略图</label>
    <div class="layui-input-block">
      <input  type="text" id="thumbnail"  name="thumbnail"  autocomplete="off" placeholder="请输入缩略图URL" class="layui-input" th:text="${text.thumbnail}" />
    </div>
</div>
<div style="width:95%;" class="layui-form-item">
	<div class="layui-form-item layui-form-text">
    <label class="layui-form-label">摘要</label>
    <div class="layui-input-block">
      <textarea style="height:50px;" id="introduction"  name ="introduction" placeholder="请输入摘要" class="layui-textarea" th:text="${text.introduction}"></textarea>
    </div>
  </div>
 </div>
 
 <div style="width:95%;" class="layui-form-item layui-form-text">
    <label class="layui-form-label">正文</label>
    <div th:if="${text.type.uid==1}"  class="layui-input-block">
      <script id="editor" type="text/plain" style="width:100%;height:450px;"></script>
    </div>
    <div th:if="${text.type.uid==2}"  class="layui-input-block" id="mdeditor">
              <textarea style="display:none;" th:text="${text.content}" />
        </div>
  </div>
  
<div class="layui-form-item">
    <div class="layui-input-block">
      <button th:if="${valid==0}" class="layui-btn" lay-submit=""  onclick="saveText()">保存</button>
      <button th:if="${valid==1}"  class="layui-btn  layui-btn-normal" lay-submit=""  onclick="saveText()">发布</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    
    </div>
  </div>
</form>
<script type="text/javascript" charset="utf-8"  src="/plugins/layui/layui.js"  />
<script type="text/javascript" charset="utf-8" src="/plugins/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/plugins/ueditor/1.4.3/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/plugins/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" charset="utf-8"  src="/plugins/jquery.1.12.4.min.js"></script>
<script type="text/javascript" charset="utf-8"  src="/plugins/mdeditor/js/editormd.js"></script> 
<script th:inline="javascript">
//js里使用thyemleafe
	var content = [[${text.content}]];
</script >  
<script>
var type = document.getElementById("typeid").value;

layui.use('element', function(){
	  var element = layui.element(); //导航的hover效果、二级菜单等功能，需要依赖element模块
	  
	  //监听导航点击
	  element.on('nav(demo)', function(elem){
	    layer.msg(elem.text());
	  });
	});
	
layui.use(['form'], function(){
	  var form = layui.form()
	  ,layer = layui.layer;
});

var ue ;

var me;
$(function() {
	if(type =='1') {
		ue =  UE.getEditor('editor');
		//延迟处理加载
		setTimeout('ueinit()',500);
	}
	if(type == '2'){
		me = editormd("mdeditor", {
        width   : "92%",
        height  : 540,
        syncScrolling : "single",
        path    : "/plugins/mdeditor/lib/"
	});}
});

function ueinit(){
	ue.execCommand('insertHtml',content);
}

function saveText(){
	if(type =='1') document.getElementById("content").value = ue.getContent();
	if(type == '2') document.getElementById("content").value = me.getMarkdown();
	document.getElementById("textForm").action = "/essay/textupdate";
	document.getElementById("textForm").target = "_self";
	document.getElementById("textForm").submit();
}
</script>
</body>
</html>